<template>
  <div style="padding: 24px">
    <fm-generate-form
      ref="generateForm"
      :data="formConfig"
    />

    <!--    <el-button @click="submit">提交</el-button>-->
    <!--    <el-button @click="reset">重置</el-button>-->
  </div>
</template>
<script>
import ConfigJson from '@/views/formManagement/FormList/config';
import { helper } from '@/utils/T';
import { GetFormConfig } from '@/api/formManagement';
export default {
  name: 'Generate',
  data() {
    return {
      remoteFuncs: {
        getSelectOptions(resolve) {
          setTimeout(() => {
            const options = [
              { value: 'value1', label: 'label1' },
              { value: 'value2', label: 'label2' },
              { value: 'value3', label: 'label3' }
            ];
            console.log(111);

            resolve(options);
          }, 0);
        }
      },
      formConfig: {
        config: {},
        list: []
      }
    };
  },
  computed: {
    defaultData: function() {
      return ConfigJson;
    }
  },
  mounted() {
    // console.log(this.$refs['generateForm']);
    this.getFormConfig();
  },
  methods: {
    getFormConfig() {
      const id = helper.getUrlParam('id');
      if (id) {
        GetFormConfig(id).then(res => {
          const { config } = res.data;
          // console.log(config);
          this.formConfig = JSON.parse(config);
        }, err => {
          this.$message.error(err.msg);
        });
      } else {
        this.$router.back();
      }
    },
    submit() {
      this.$refs['generateForm'].getData().then(data => {
        console.log(data);
      }).catch(err => {
        console.log(err);
      });
    },
    reset() {
      this.$refs['generateForm'].reset();
    }
  }
};
</script>

<style scoped>

</style>
